<script setup lang="ts">

import { EnumBetResult, EnumBjlResult } from '@/models/enums/EnumBjlResult';
import { ExcutePlan, RoundInfo } from '@/models/execute/ExecutePlan';
import { onMounted, reactive, ref, nextTick, getCurrentInstance } from 'vue';
import WisdomRecmStrategyDebug from '../components/debug/WisdomRecmStrategyDebug.vue';
import WisdomMoneyStrategyV29Debug from '../components/debug/WisdomMoneyStrategyV29Debug.vue';
import { useRoute } from 'vue-router';
import { compression, decompress } from '@/utils/compress';
import { PickerOption, showConfirmDialog } from 'vant';
import { FixedStrategy, FixedValueStrategy } from '@/models/execute/recmStrategy/FixedStrategy';
import { LdStepMoneyStrategy } from '@/models/execute/moneyStrategy/LdStepMoneyStrategy';
import { BossRabbitMoneyStrategy, ResetRecmRabbitMoneyStrategy } from '@/models/execute/moneyStrategy/BossRabitMoneyStrategy';
import { IPlan } from '@/models/execute/IExecutePlan';
import { ArrayStrategy } from '@/models/execute/recmStrategy/ArrayStrategy';
import { FollowStrategy } from '@/models/execute/recmStrategy/FollowStrategy';
import { NormalStepMoneyStrategy } from '@/models/execute/moneyStrategy/NormalStepMoneyStrategy';


defineOptions({
    components: { WisdomRecmStrategyDebug, WisdomMoneyStrategyV29Debug }
})

let route = useRoute();
const debug = ref(false);
debug.value = route.query.debug ? true : false;

const nextTableReset = ref(false);
if ((route.query.ntr?.toString() ?? "") == "true" || (route.query.ntr?.toString() ?? "") == "") {
    nextTableReset.value = true;
}

const roundInfo = reactive<RoundInfo>(new RoundInfo());


const showTab = ref(['showResult']);
const resultInputCompoenent = ref<any>(null);
const resultComponent = ref<any>(null);
let planSum = ref(0);

let game = reactive(new ExcutePlan());
let planA = reactive(new ExcutePlan());
let planB = reactive(new ExcutePlan());
let planC = reactive(new ExcutePlan());
let planD = reactive(new ExcutePlan());
let planE = reactive(new ExcutePlan());
let planF = reactive(new ExcutePlan());
let planG = reactive(new ExcutePlan());
let planH = reactive(new ExcutePlan());
let planI = reactive(new ExcutePlan());
let mfz = reactive(new ExcutePlan());
let mff = reactive(new ExcutePlan());

let tempArray = [planA, planB];
const planArray = reactive(tempArray);
const planBStart = 4;
const initData = () => {
    let newRound = new RoundInfo();
    Object.assign(roundInfo, newRound);
    resultInputCompoenent.value?.initData();
    resultComponent.value?.initData();
    snapShot.splice(0, snapShot.length);
    planSum.value = 0;

    let newGame = new ExcutePlan();
    Object.assign(game, newGame);

    let multiple = planA.multiple;
    let newPlanA = new ExcutePlan();
    Object.assign(planA, newPlanA);
    planA.planName = 'A计划';
    planA.multiple = multiple;
    planA.recmStrategy = [
        new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })
    ];
    planA.moneyStrategy = [
        new LdStepMoneyStrategy("ld-money-strategy", {
            winStep: -1,
            failStep: 1,
            baseMoney: 10,
            index: 1,
            recmMoney: 10,
            stepMoney: 10,
            stopCount: -3
        })
    ];
    planA.toResult(new RoundInfo());

    let newPlanB = new ExcutePlan();
    multiple = planB.multiple;
    Object.assign(planB, newPlanB);
    planB.running = false;
    planB.planName = 'B计划';
    planB.multiple = multiple;
    planB.recmStrategy = [
        new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })
    ];
    planB.moneyStrategy = [
        new BossRabbitMoneyStrategy("ai-money-strategy")
    ];
    planB.toResult(new RoundInfo());


    let newPlanC = new ExcutePlan();
    multiple = planC.multiple;
    Object.assign(planC, newPlanC);
    planC.planName = 'C计划';
    planC.multiple = multiple;
    planC.recmStrategy = [
        new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })
    ];
    planC.moneyStrategy = [
        new LdStepMoneyStrategy("ld-money-strategy", {
            winStep: -1,
            failStep: 1,
            baseMoney: 10,
            index: 1,
            recmMoney: 10,
            stepMoney: 10,
            stopCount: -3
        })
    ];
    planC.toResult(new RoundInfo());

    let newPlanD = new ExcutePlan();
    multiple = planD.multiple;
    Object.assign(planD, newPlanD);
    planD.running = false;
    planD.planName = 'D计划';
    planD.multiple = multiple;
    planD.recmStrategy = [
        new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })
    ];
    planD.moneyStrategy = [
        new BossRabbitMoneyStrategy("ai-money-strategy")
    ];
    planD.toResult(new RoundInfo());

    let newPlanE = new ExcutePlan();
    multiple = planE.multiple;
    Object.assign(planE, newPlanE);
    planE.planName = "E计划";
    planE.multiple = multiple;
    planE.recmStrategy = [
        new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })
    ];
    planE.moneyStrategy = [new BossRabbitMoneyStrategy("方案一", {
        baseMoney: 10,
        winStep: 1,
        failStep: -2,
        prevMoney: 0,
        currentMoney: 10,
        prevPrevMoney: 0,
        maxMoney: 9999999999,
        changeMoney: 999999999
    })];
    [planE.recmInfo.recmV, planE.recmInfo.recmMoney] = planE.toMoney(new RoundInfo(), planE.recmInfo, planE.userRecmInfo, planE.baseMoney);

    var newPlanF = new ExcutePlan();
    multiple = planF.multiple;
    Object.assign(planF, newPlanF);
    planF.planName = "F计划";
    planF.multiple = multiple;
    planF.recmStrategy = [
        new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })
    ];
    planF.moneyStrategy = [new BossRabbitMoneyStrategy("方案二", {
        baseMoney: 10,
        winStep: 1,
        failStep: -2,
        prevMoney: 0,
        currentMoney: 10,
        prevPrevMoney: 0,
        maxMoney: 9999999999,
        changeMoney: 999999999,
    })];
    [planF.recmInfo.recmV, planF.recmInfo.recmMoney] = planF.toMoney(new RoundInfo(), planF.recmInfo, planF.userRecmInfo, planF.baseMoney);

    var newPlanG = new ExcutePlan();
    multiple = planG.multiple;
    Object.assign(planG, newPlanG);
    planG.planName = "G计划";
    planG.multiple = multiple;
    planG.recmStrategy = [new FollowStrategy({ followCount: 2, reverse: false })];
    planG.moneyStrategy = [new BossRabbitMoneyStrategy("ai-money-strategy", {
        baseMoney: 10,
        winStep: 1,
        failStep: 0,
        prevMoney: 0,
        currentMoney: 10,
    })];

    // var newPlanH = new ExcutePlan();
    // multiple = planH.multiple;
    // Object.assign(planH, newPlanH);
    // planH.planName = "H计划";
    // planH.multiple = multiple;
    // planH.recmStrategy = [
    //     new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })
    // ];
    // planH.moneyStrategy = [new BossRabbitMoneyStrategy("方案二", {
    //     baseMoney: 10,
    //     winStep: 1,
    //     failStep: 0,
    //     prevMoney: 0,
    //     currentMoney: 10,
    //     prevPrevMoney: 0,
    //     maxMoney: 9999999999,
    //     changeMoney: 999999999,
    // })];
    // [planH.recmInfo.recmV, planH.recmInfo.recmMoney] = 
    // planH.toMoney(new RoundInfo(), planH.recmInfo, planH.userRecmInfo, planH.baseMoney);

    // var newPlanI = new ExcutePlan();
    // multiple = planI.multiple;
    // Object.assign(planI, newPlanI);
    // planI.planName = "I计划";
    // planI.multiple = multiple;
    // planI.recmStrategy = [new FollowStrategy({ followCount: 2, reverse: false })];
    // planI.moneyStrategy = [new BossRabbitMoneyStrategy("方案二", {
    //     baseMoney: 10,
    //     winStep: 1,
    //     failStep: 0,
    //     prevMoney: 0,
    //     currentMoney: 10,
    //     prevPrevMoney: 0,
    //     maxMoney: 9999999999,
    //     changeMoney: 999999999,
    // })];
    // [planI.recmInfo.recmV, planI.recmInfo.recmMoney] = 
    // planH.toMoney(new RoundInfo(), planI.recmInfo, planI.userRecmInfo, planI.baseMoney);

    var newMfz = new ExcutePlan();
    multiple = mfz.multiple;
    Object.assign(mfz, newMfz);
    mfz.planName = "复正";
    mfz.recmStrategy = [new FixedValueStrategy({ reverse: false, result: EnumBjlResult.Z })];
    mfz.moneyStrategy = [new NormalStepMoneyStrategy("方案一", {
        baseMoney: 10,
        startMoney: 10,
        addStep: 10,
        devideStep: -10,
        reverse: false,
        resetLevel: 80,
    }, true)];
    [mfz.recmInfo.recmV, mfz.recmInfo.recmMoney] =
        mfz.toMoney(new RoundInfo(), mfz.recmInfo, mfz.userRecmInfo, mfz.baseMoney);


    var newMff = new ExcutePlan();
    multiple = mff.multiple;
    Object.assign(mff, newMff);
    mff.planName = "复正";
    mff.recmStrategy = [new FixedValueStrategy({ reverse: false, result: EnumBjlResult.X })];
    mff.moneyStrategy = [new NormalStepMoneyStrategy("方案一", {
        baseMoney: 10,
        startMoney: 10,
        addStep: 10,
        devideStep: -10,
        reverse: false,
        resetLevel: 80,
    }, true)];
    [mff.recmInfo.recmV, mff.recmInfo.recmMoney] =
        mff.toMoney(new RoundInfo(), mff.recmInfo, mff.userRecmInfo, mff.baseMoney);

    planArray.splice(0, planArray.length);
    planArray.push(planA);
    planArray.push(planB);
    planArray.push(planC);
    planArray.push(planD);
    planArray.push(planE);
    planArray.push(planF);
    planArray.push(planG);
    // planArray.push(planH);
    // planArray.push(planI);
    planArray.push(mfz);
    planArray.push(mff);

};

onMounted(() => {
    initData();
    nextTick(() => {
        showTab.value = ['showResult'];
    })

});
const setResult = (result: EnumBjlResult) => {
    roundInfo.results.push(result)
    roundInfo.currentResult = result;
    resultInputCompoenent.value.setResult(result);

    if (game.recmInfo.recmV != EnumBjlResult.U) {
        resultComponent.value?.setResult(result == game.recmInfo.recmV ? 1 : 0);
    }
    else {
        resultComponent.value?.record();
    }

    game.setResult(roundInfo, game.recmInfo, game.multiple, game.waterRate, game.fuliRate);

    let planAPrevRecmMoney = planA.recmInfo.recmMoney;
    let planARoundInfo = Object.assign({}, roundInfo);
    planA.setResult(planARoundInfo, planA.recmInfo, planA.multiple, planA.waterRate, planA.fuliRate);
    let planAUserRecmV = planA.toResult(roundInfo);
    planARoundInfo.userRecm = planAUserRecmV;
    planA.userRecmInfo.recmV = planAUserRecmV;
    let [planARecmV, planARecmMoney] = planA.toMoney(planARoundInfo, planA.recmInfo, planA.userRecmInfo, planA.baseMoney);
    planA.recmInfo.recmV = planARecmV;
    planA.recmInfo.recmMoney = planARecmMoney;

    let money = 0;
    if (planA.recmInfo.recmV == EnumBjlResult.Z) {
        money += (planA.recmInfo.recmMoney * planA.multiple);
    }
    else if (planA.recmInfo.recmV == EnumBjlResult.X) {
        money -= (planA.recmInfo.recmMoney * planA.multiple);
    }

    if (planA.recmInfo.summaryInfo.lfail >= planBStart && !planB.running) {
        planB.running = true;
        planB.moneyStrategy = [new BossRabbitMoneyStrategy("", {
            baseMoney: planAPrevRecmMoney,
            winStep: 1,
            failStep: 0,
            prevMoney: 0,
            currentMoney: planAPrevRecmMoney,
            prevPrevMoney: 0,
            maxMoney: 9999999999,
            changeMoney: 9999999999
        })]
    }
    if (planB.running) {
        let planBRoundInfo = Object.assign({}, roundInfo);
        planBRoundInfo.userRecm = planA.recmInfo.recmV;
        planB.setResult(roundInfo, planB.recmInfo, planB.multiple, planB.waterRate, planB.fuliRate);
        if (planB.recmInfo.summaryInfo.prevResult == EnumBetResult.Fail) {
            planB.recmInfo.recmV = EnumBjlResult.U;
            planB.recmInfo.recmMoney = 0;
            planB.running = false;
        }
        else {
            let planBUserRecmV = planB.toResult(planBRoundInfo);
            planBRoundInfo.userRecm = planBUserRecmV;
            planB.userRecmInfo.recmV = planBUserRecmV; //game.recmInfo.recmV;
            let [planBRecmV, planBRecmMoney] = planB.toMoney(planBRoundInfo, planB.recmInfo, planB.userRecmInfo, planB.baseMoney);
            planB.recmInfo.recmV = planBRecmV;
            planB.recmInfo.recmMoney = planBRecmMoney;
        }

        if (planB.recmInfo.recmV == EnumBjlResult.Z) {
            money += (planB.recmInfo.recmMoney * planB.multiple);
        }
        else if (planB.recmInfo.recmV == EnumBjlResult.X) {
            money -= (planB.recmInfo.recmMoney * planB.multiple);
        }
    }

    let planCPrevRecmMoney = planC.recmInfo.recmMoney;
    let planCRoundInfo = Object.assign({}, roundInfo);
    planC.setResult(planCRoundInfo, planC.recmInfo, planC.multiple, planC.waterRate, planC.fuliRate);
    let planCUserRecmV = planC.toResult(roundInfo);
    planCRoundInfo.userRecm = planCUserRecmV;
    planC.userRecmInfo.recmV = planCUserRecmV; //game.recmInfo.recmV;
    let [planCRecmV, planCRecmMoney] = planC.toMoney(planCRoundInfo, planC.recmInfo, planC.userRecmInfo, planC.baseMoney);
    planC.recmInfo.recmV = planCRecmV;
    planC.recmInfo.recmMoney = planCRecmMoney;

    if (planC.recmInfo.recmV == EnumBjlResult.Z) {
        money += (planC.recmInfo.recmMoney * planC.multiple);
    }
    else if (planC.recmInfo.recmV == EnumBjlResult.X) {
        money -= (planC.recmInfo.recmMoney * planC.multiple);
    }

    if (planC.recmInfo.summaryInfo.lfail >= planBStart && !planD.running) {
        planD.running = true;
        planD.moneyStrategy = [new BossRabbitMoneyStrategy("", {
            baseMoney: planCPrevRecmMoney,
            winStep: 1,
            failStep: 0,
            prevMoney: 0,
            currentMoney: planCPrevRecmMoney,
            prevPrevMoney: 0,
            maxMoney: 9999999999,
            changeMoney: 9999999999
        })]
    }
    if (planD.running) {
        let planDRoundInfo = Object.assign({}, roundInfo);
        planDRoundInfo.userRecm = planC.recmInfo.recmV;
        planD.setResult(roundInfo, planD.recmInfo, planD.multiple, planD.waterRate, planD.fuliRate);
        if (planD.recmInfo.summaryInfo.prevResult == EnumBetResult.Fail) {
            planD.recmInfo.recmV = EnumBjlResult.U;
            planD.recmInfo.recmMoney = 0;
            planD.running = false;
        }
        else {
            let planDUserRecmV = planD.toResult(planDRoundInfo);
            planDRoundInfo.userRecm = planDUserRecmV;
            planD.userRecmInfo.recmV = planDUserRecmV;
            let [planBRecmV, planBRecmMoney] = planD.toMoney(planDRoundInfo, planD.recmInfo, planD.userRecmInfo, planD.baseMoney);
            planD.recmInfo.recmV = planBRecmV;
            planD.recmInfo.recmMoney = planBRecmMoney;
        }

        if (planD.recmInfo.recmV == EnumBjlResult.Z) {
            money += (planD.recmInfo.recmMoney * planD.multiple);
        }
        else if (planD.recmInfo.recmV == EnumBjlResult.X) {
            money -= (planD.recmInfo.recmMoney * planD.multiple);
        }
    }

    let planFZRoundInfo = Object.assign({}, roundInfo);
    planE.setResult(planFZRoundInfo, planE.recmInfo, planE.multiple, planE.waterRate, planE.fuliRate);
    let planFZUserRecmV = planE.toResult(roundInfo);
    planFZRoundInfo.userRecm = planFZUserRecmV;
    planE.userRecmInfo.recmV = planFZUserRecmV;
    let [planFZRecmV, planFZRecmMoney] = planE.toMoney(planFZRoundInfo, planE.recmInfo, planE.userRecmInfo, planE.baseMoney);
    planE.recmInfo.recmV = planFZRecmV;
    planE.recmInfo.recmMoney = planFZRecmMoney;
    if (planE.recmInfo.recmV == EnumBjlResult.Z) {
        money += (planE.recmInfo.recmMoney * planE.multiple);
    }
    else if (planE.recmInfo.recmV == EnumBjlResult.X) {
        money -= (planE.recmInfo.recmMoney * planE.multiple);
    }

    let planFFRoundInfo = Object.assign({}, roundInfo);
    planF.setResult(planFFRoundInfo, planF.recmInfo, planF.multiple, planF.waterRate, planF.fuliRate);
    let planFFUserRecmV = planF.toResult(roundInfo);
    planFFRoundInfo.userRecm = planFFUserRecmV;
    planF.userRecmInfo.recmV = planFFUserRecmV;
    let [planFFRecmV, planFFRecmMoney] = planF.toMoney(planFFRoundInfo, planF.recmInfo, planF.userRecmInfo, planF.baseMoney);
    planF.recmInfo.recmV = planFFRecmV;
    planF.recmInfo.recmMoney = planFFRecmMoney;

    if (planF.recmInfo.recmV == EnumBjlResult.Z) {
        money += (planF.recmInfo.recmMoney * planF.multiple);
    }
    else if (planF.recmInfo.recmV == EnumBjlResult.X) {
        money -= (planF.recmInfo.recmMoney * planF.multiple);
    }


    let planGRoundInfo = Object.assign({}, roundInfo);
    planG.setResult(planGRoundInfo, planG.recmInfo, planG.multiple, planG.waterRate, planG.fuliRate);
    let planGUserRecmV = planG.toResult(roundInfo);
    planGRoundInfo.userRecm = planGUserRecmV;
    planG.userRecmInfo.recmV = planGUserRecmV;
    let [planGRecmV, planGRecmMoney] = planG.toMoney(planGRoundInfo, planG.recmInfo, planG.userRecmInfo, planG.baseMoney);
    planG.recmInfo.recmV = planGRecmV;
    planG.recmInfo.recmMoney = planGRecmMoney;

    if (planG.recmInfo.recmV == EnumBjlResult.Z) {
        money += (planG.recmInfo.recmMoney * planG.multiple);
    }
    else if (planG.recmInfo.recmV == EnumBjlResult.X) {
        money -= (planG.recmInfo.recmMoney * planG.multiple);
    }

    // let planHRoundInfo = Object.assign({}, roundInfo);
    // planH.setResult(planHRoundInfo, planH.recmInfo, planH.multiple, planH.waterRate, planH.fuliRate);
    // let planHUserRecmV = planH.toResult(roundInfo);
    // planHRoundInfo.userRecm = planHUserRecmV;
    // planH.userRecmInfo.recmV = planHUserRecmV;
    // let [planHRecmV, planHRecmMoney] = planH.toMoney(planHRoundInfo, planH.recmInfo, planH.userRecmInfo, planH.baseMoney);
    // planH.recmInfo.recmV = planHRecmV;
    // planH.recmInfo.recmMoney = planHRecmMoney;

    // if (planH.recmInfo.recmV == EnumBjlResult.Z) {
    //     money += (planH.recmInfo.recmMoney * planH.multiple);
    // }
    // else if (planH.recmInfo.recmV == EnumBjlResult.X) {
    //     money -= (planH.recmInfo.recmMoney * planH.multiple);
    // }

    // let planIRoundInfo = Object.assign({}, roundInfo);
    // planI.setResult(planIRoundInfo, planI.recmInfo, planI.multiple, planI.waterRate, planI.fuliRate);
    // let planIUserRecmV = planI.toResult(roundInfo);
    // planIRoundInfo.userRecm = planIUserRecmV;
    // planI.userRecmInfo.recmV = planIUserRecmV;
    // let [planIRecmV, planIRecmMoney] = planI.toMoney(planIRoundInfo, planI.recmInfo, planI.userRecmInfo, planI.baseMoney);
    // planI.recmInfo.recmV = planIRecmV;
    // planI.recmInfo.recmMoney = planIRecmMoney;

    // if (planI.recmInfo.recmV == EnumBjlResult.Z) {
    //     money += (planI.recmInfo.recmMoney * planI.multiple);
    // }
    // else if (planI.recmInfo.recmV == EnumBjlResult.X) {
    //     money -= (planI.recmInfo.recmMoney * planI.multiple);
    // }

    let planMFZRoundInfo = Object.assign({}, roundInfo);
    mfz.setResult(planMFZRoundInfo, mfz.recmInfo, mfz.multiple, mfz.waterRate, mfz.fuliRate);
    let planMFZUserRecmV = mfz.toResult(roundInfo);
    planMFZRoundInfo.userRecm = planMFZUserRecmV;
    mfz.userRecmInfo.recmV = planMFZUserRecmV;
    let [planMfzRecmV, planMfzRecmMoney] = mfz.toMoney(planMFZRoundInfo, mfz.recmInfo, mfz.userRecmInfo, mfz.baseMoney);
    mfz.recmInfo.recmV = planMfzRecmV;
    mfz.recmInfo.recmMoney = planMfzRecmMoney;

    if (mfz.recmInfo.recmV == EnumBjlResult.Z) {
        money += (mfz.recmInfo.recmMoney * mfz.multiple);
    }
    else if (mfz.recmInfo.recmV == EnumBjlResult.X) {
        money -= (mfz.recmInfo.recmMoney * mfz.multiple);
    }

    let planMFFRoundInfo = Object.assign({}, roundInfo);
    mff.setResult(planMFFRoundInfo, mff.recmInfo, mff.multiple, mff.waterRate, mff.fuliRate);
    let planMFFUserRecmV = mff.toResult(roundInfo);
    planMFFRoundInfo.userRecm = planMFFUserRecmV;
    mff.userRecmInfo.recmV = planMFFUserRecmV;
    let [planMffRecmV, planMffRecmMoney] = mff.toMoney(planMFFRoundInfo, mff.recmInfo, mff.userRecmInfo, mff.baseMoney);
    mff.recmInfo.recmV = planMffRecmV;
    mff.recmInfo.recmMoney = planMffRecmMoney;

    if (mff.recmInfo.recmV == EnumBjlResult.Z) {
        money += (mff.recmInfo.recmMoney * mff.multiple);
    }
    else if (mff.recmInfo.recmV == EnumBjlResult.X) {
        money -= (mff.recmInfo.recmMoney * mff.multiple);
    }

    if (money > 0) {
        game.recmInfo.recmV = EnumBjlResult.Z;
        game.recmInfo.recmMoney = Math.abs(money);
    }
    else if (money < 0) {
        game.recmInfo.recmV = EnumBjlResult.X;
        game.recmInfo.recmMoney = Math.abs(money);
    }
    else {
        game.recmInfo.recmV = EnumBjlResult.U;
        game.recmInfo.recmMoney = 0;
    }

    let sum = 0;
    planArray.forEach(plan => {
        sum += (plan.recmInfo.summaryInfo.winMoney - plan.recmInfo.summaryInfo.failMoney);
    })
    planSum.value = sum;
    record();

};
const showMoney = () => {
    let money = 0;
    planArray.forEach(plan => {
        let [recmV, recmMoney] = plan.showMoney();
        if (recmV == EnumBjlResult.Z) {
            money += (recmMoney * plan.multiple);
        }
        else if (recmV == EnumBjlResult.X) {
            money -= (recmMoney * plan.multiple);
        }
    })
    if (money > 0) {
        game.recmInfo.recmV = EnumBjlResult.Z;
        game.recmInfo.recmMoney = Math.abs(money);
    }
    else if (money < 0) {
        game.recmInfo.recmV = EnumBjlResult.X;
        game.recmInfo.recmMoney = Math.abs(money);
    }
    else {
        game.recmInfo.recmV = EnumBjlResult.U;
        game.recmInfo.recmMoney = 0;
    }
};

const snapShot: string[] = [];

type SnapObject = {
    game: ExcutePlan,
    roundInfo: RoundInfo,
    planA: ExcutePlan,
    planB: ExcutePlan,
    planC: ExcutePlan,
    planD: ExcutePlan,
    planE: ExcutePlan,
    planF: ExcutePlan,
    planG: ExcutePlan,
    mfz:ExcutePlan,
    mff:ExcutePlan,
    planSum: number
}
const record = () => {
    snapShot.push(compression({
        game,
        roundInfo,
        planA,
        planB,
        planC,
        planD,
        planE,
        planF,
        planG,
        planSum: planSum.value,
        mfz,
        mff
    }));
};

const resetGame = () => {
    showConfirmDialog({
        title: '提示',
        message: '确认重新开始吗？',
        width: '80%'
    }).then(() => {
        // on close
        initData();
    });
};

const revert = () => {

    resultInputCompoenent.value.revert();
    let revertRound = snapShot.pop();
    if (revertRound) {
        let revertObj = decompress(revertRound) as SnapObject;
        let game = revertObj.game;
        resultComponent.value?.revert();
    }


    let top = snapShot[snapShot.length - 1];
    if (top) {
        let topObj = decompress(top) as SnapObject;

        if (topObj.roundInfo) roundInfo.copyValue(topObj.roundInfo);
        if (topObj.game) game.copyValue(topObj.game);
        if (topObj.planA) planA.copyValue(topObj.planA);
        if (topObj.planB) planB.copyValue(topObj.planB);
        if (topObj.planC) planC.copyValue(topObj.planC);
        if (topObj.planD) planD.copyValue(topObj.planD);
        if (topObj.planE) planE.copyValue(topObj.planE);
        if (topObj.planF) planF.copyValue(topObj.planF);
        if (topObj.planG) planG.copyValue(topObj.planG);
        if (topObj.mfz) mfz.copyValue(topObj.mfz);
        if (topObj.mff) mff.copyValue(topObj.mff);
        planSum.value = topObj.planSum;

    }
    else {
        initData();
    }
};
const nextTable = () => {

    showConfirmDialog({
        title: '提示',
        message: '确认换桌吗',
        width: '80%'
    }).then(() => {
        // on close
        resultInputCompoenent.value.nextTable();
        resultComponent.value?.nextTable();
        roundInfo.changeCount++;

        snapShot.push(compression({ game, roundInfo }));
    });

}



const showMultiplePicker = ref(false);
let plan: IPlan | null;
const showMultipleDialog = (pl: IPlan) => {
    plan = pl;
    showMultiplePicker.value = true;

};
const cancelMultipleDialog = () => {
    plan = null;
    showMultiplePicker.value = false;
};
const selectMultiple = ({ selectedOptions }: PickerOption) => {
    let v = parseFloat(selectedOptions[0].value?.toString() ?? "");
    if (isNaN(v)) v = 1;
    if (plan) {
        plan.multiple = v;
    }
    showMultiplePicker.value = false;
    showMoney();
};

const pickerColumns: PickerOption[] = [];
for (let i = -1; i < 20; i++) {
    pickerColumns.push({ text: (i + 1), value: (i + 1) });
}
</script>
<template>

    <!-- 底部弹出 -->
    <van-popup v-model:show="showMultiplePicker" position="bottom" :style="{ height: '50%' }">
        <van-picker title="请选择倍率" :columns="pickerColumns" @cancel="cancelMultipleDialog" @confirm="selectMultiple" />
    </van-popup>


    <van-row>
        <van-col :offset="1" :span="23">
            <BjlInput ref="resultInputCompoenent" />
        </van-col>
    </van-row>


    <van-divider :margin="24" style="margin:0;" />

    <van-row class="recm-item">
        <van-col v-if="game.recmInfo.recmV == EnumBjlResult.X" class="recm x" :span="12">
            {{ parseInt((game.recmInfo.recmMoney * game.multiple).toFixed(0)) }}
        </van-col>
        <van-col v-else :span="12" class="recm"></van-col>

        <van-col :span="12" v-if="game.recmInfo.recmV == EnumBjlResult.Z" class="recm z">
            {{ parseInt((game.recmInfo.recmMoney * game.multiple).toFixed(0)) }}
        </van-col>
        <van-col v-else :span="12" class="recm"></van-col>
    </van-row>

    <van-row>
        <van-col :span="24">
            <van-collapse v-model="showTab">
                <van-collapse-item name="showResult">
                    <template #title>
                        <van-row style="text-align: center;">
                            <van-col offset="1" :span="7">
                                <span style="color:red;">{{ game.recmInfo.summaryInfo.winCount }}</span>
                                -
                                <span style="color:blue;">{{ game.recmInfo.summaryInfo.failCount }}</span>
                            </van-col>
                            <van-col :span="10">
                                <span :style="[
                                    game.recmInfo.summaryInfo.winCount > game.recmInfo.summaryInfo.failCount ? { 'color': 'red' }
                                        : game.recmInfo.summaryInfo.winCount < game.recmInfo.summaryInfo.failCount ? { 'color': 'blue' } : ''
                                ]">{{ game.recmInfo.summaryInfo.winCount - game.recmInfo.summaryInfo.failCount
                                    }}</span>
                            </van-col>
                            <van-col :span="6">

                                <span
                                    v-if="(game.recmInfo.summaryInfo.winCount + game.recmInfo.summaryInfo.failCount) > 0"
                                    :style="[
                                        game.recmInfo.summaryInfo.winCount > game.recmInfo.summaryInfo.failCount ? { 'color': 'red' }
                                            : game.recmInfo.summaryInfo.winCount < game.recmInfo.summaryInfo.failCount ? { 'color': 'blue' } : ''
                                    ]">
                                    {{ (game.recmInfo.summaryInfo.winCount / (game.recmInfo.summaryInfo.winCount +
                                        game.recmInfo.summaryInfo.failCount)).toFixed(2) }}
                                </span>
                                <span v-else>0.00</span>
                            </van-col>
                        </van-row>
                    </template>
                    <BjlResult ref="resultComponent" labelName="运势路" />
                </van-collapse-item>
            </van-collapse>
        </van-col>
    </van-row>

    <van-row class="recm-item">
        <van-col :span="6" :style="[
            (planSum > 0) ? { 'color': 'red' }
                : (planSum < 0) ? { 'color': 'blue' } : ''
        ]">
            {{ planSum.toFixed(0) }}
        </van-col>
        <van-col :span="6" style="color:red;">
            {{ game.recmInfo.summaryInfo.fuliMoney.toFixed(0) }}
        </van-col>
        <van-col :span="6" style="color:blue;">
            {{ game.recmInfo.summaryInfo.waterMoney.toFixed(0) }}
        </van-col>
        <van-col :span="6" :style="[
            (game.recmInfo.summaryInfo.winMoney -
                game.recmInfo.summaryInfo.failMoney -
                game.recmInfo.summaryInfo.waterMoney > 0) ? { 'color': 'red' }
                : (game.recmInfo.summaryInfo.winMoney -
                    game.recmInfo.summaryInfo.failMoney -
                    game.recmInfo.summaryInfo.waterMoney < 0) ? { 'color': 'blue' } : ''
        ]">
            {{ (game.recmInfo.summaryInfo.winMoney -
                game.recmInfo.summaryInfo.failMoney -
                game.recmInfo.summaryInfo.waterMoney).toFixed(0) }}
        </van-col>
    </van-row>

    <van-row class="operate">
        <van-col :span="6">
            <van-button class="BSync" @click="revert">撤销</van-button>
        </van-col>
        <van-col :span="6">
            <van-button class="BSync" @click="resetGame">重置</van-button>
        </van-col>
        <van-col :span="6">
            <van-button class="BSync" @click="nextTable">换桌</van-button>
        </van-col>
        <van-col :span="6">
            <van-button style="width:75px" class="BSync" @click="showMultipleDialog(game)">{{ game.multiple
                }}</van-button>
        </van-col>
    </van-row>
    <van-row justify="center" class="recm-item" style="margin:40px 0;">
        <van-col offset="1" :span="10" class="recm x" @click="setResult(EnumBjlResult.X)">&nbsp;</van-col>
        <van-col offset="1" :span="10" class="recm z" @click="setResult(EnumBjlResult.Z)">&nbsp;</van-col>
    </van-row>


    <van-row class="debug item" v-for="(plan, idx) in planArray">
        <van-col :span="3" :offset="1">
            <van-button class="BSync" @click.stop="showMultipleDialog(plan)">{{ plan.multiple }}</van-button>
        </van-col>
        <van-col :span="5">{{ plan.planName }}</van-col>
        <van-col :span="3">
            <span v-if="plan.recmInfo.recmV == EnumBjlResult.Z" class="recm" style="background-color: red;">{{
                plan.recmInfo.recmMoney * plan.multiple }}</span>
            <span v-else-if="plan.recmInfo.recmV == EnumBjlResult.X" class="recm" style="background-color: blue;">{{
                plan.recmInfo.recmMoney * plan.multiple }}</span>
            <span v-else></span>
        </van-col>
        <van-col :span="4">
            <span :style="[
                plan.recmInfo.summaryInfo.winMoney > plan.recmInfo.summaryInfo.failMoney ? { 'color': 'red' }
                    : plan.recmInfo.summaryInfo.winMoney < plan.recmInfo.summaryInfo.failMoney ? { 'color': 'blue' } : ''
            ]">{{ plan.recmInfo.summaryInfo.winMoney - plan.recmInfo.summaryInfo.failMoney }}</span>
        </van-col>
        <van-col :span="6">
            <span style="color:red;"> {{ plan.recmInfo.summaryInfo.winCount }}</span>
            -
            <span style="color:blue;">{{ plan.recmInfo.summaryInfo.failCount }}</span>
        </van-col>
    </van-row>
</template>

<style scoped>
.st {
    font-size: 16px;
    text-align: center;
    height: 30px;
    line-height: 30px;
}

.operate {
    text-align: center;
    height: auto;
    margin: 5px 0;
}

.recm-item {
    margin: 5px 0;

    div {
        align-items: center;
        color: coral;
        height: 40px;
        line-height: 40px;
        text-align: center;
        justify-content: center;
        flex-direction: column;
        font-size: 16px;
    }

    .recm {
        border-radius: 0;
        /* line-height: 40px; */
        padding: 5px 30px;
        width: 100%;
        font-size: 24px;
    }

    .recm.x {
        color: white;
        background-color: blue;

    }

    .recm.z {
        color: white;
        background-color: red;
    }

    .urecm {
        width: 13px;
        height: 13px;
        border-radius: 90px;
        display: inline-block;

    }

    .urecm.z {
        border: 1px solid red;
    }

    .urecm.x {
        border: 1px solid blue;
    }
}

.tab-item {
    div {
        align-items: center;
        color: black;
        height: 15px;
        line-height: 15px;
        text-align: center;
        justify-content: center;
        flex-direction: column;
        font-size: 16px;
    }

    .recm {
        border-radius: 0;
        /* line-height: 40px; */
        padding: 5px 6px;
        width: 30px;
        font-size: 16px;
    }

    .recm.x {
        color: white;
        background-color: blue;

    }

    .recm.z {
        color: white;
        background-color: red;
    }
}


div.recm {
    display: inline-block;
    width: 15px;
    height: 15px;
    border-radius: 90px;
}

div.Z {
    border: 3px solid red;
}

div.X {
    border: 3px solid blue;
}

div.B {
    border: 3px solid rgb(6, 237, 83);
}

.operate button,
.operate_button button {
    font-size: 12px;
    color: white;
    border: none;
    margin: 5px 15px;
    padding: 10px;
}

.BZ {
    background-color: #ae2a2a;
    color: red !important;
}

.BX {
    background-color: #2a71ae;
    color: blue !important;
}

.BSync {
    background-color: coral;
    color: white;
    height: 30px;
    width: 45px;
}

.revert {
    background-color: #c0c0c0;
}

.change {
    background-color: darkgoldenrod;
}

.restart {
    background-color: rgb(244, 0, 252);
}

.changetable {
    background-color: cadetblue;
}

.debug.item {
    font-size: 14px;
    margin: 5px 0;
    width: 100%;
    text-align: center;


    .recm {
        color: white;
        height: 30px;
        width: 40px;
        font-size: 12px;
        display: inline-block;
        line-height: 30px;
    }
}
</style>